package january.test_1_26;

import java.util.Scanner;

public class TestMain1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        int[] dp = new int[n+1];
        int max = 0;
        for(int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        for(int i = 1; i <= n; i++) {
            dp[i] = dp[i-1] + arr[i];
        }
        for(int i = 1; i <= n+1; i++) {
            for(int j = i; j <= n+1; j++) {
                int tmp = dp[j] - dp[i];
                if(tmp > max) {
                    max = tmp;
                }
            }
        }
        System.out.println(max);
    }
}
